import React , { useEffect,useState }from 'react';
import {  Button, Table,  } from 'antd'
import { useNavigate } from 'react-router-dom';
import TimeList from "../../components/chen/TimeList";
import '../../styles/chen/systemconsut.scss'
import * as service from  '../../api/chen/index'
interface Props{

}
function SystemConsut(props: Props) {
  var navigate=useNavigate()
const [data,setData]=useState([])
    // const data = [

    //     {
    //      id: '1',
    //      pic:'',
    //       articletitle: '如何守护自己的肠道健康?',
    //       articlekind:'健康头条',
    //       person: "李明明",
    //       pbulishStasus:'已发布',
    //       collaction:'130',
    //       endingtime: 'New York No. 1 Lake Park',
            
    //         description:''
    //     },
    //     {

    //      id: '2',
    //      pic:'',
    //       articletitle: '如何守护自己的肠道健康?',
    //       articlekind:'健康头条',
    //     person: "李明明",
    //     pbulishStasus:'已发布',
    //     collaction:'130',
              
    //       endingtime: 'London No. 1 Lake Park',
         
    //       description:''
    //     },
    //     {
    //      id: '3',
    //      pic:'',
    //       articletitle: '如何守护自己的肠道健康?',
    //       articlekind:'健康头条',
    //       person: "李明明",
    //       pbulishStasus:'已发布',
    //       collaction:'130',
    //       endingtime: 'Sidney No. 1 Lake Park',
          
    //         description:''
    //     },
    //   ];
       useEffect(() => {
    service.consut_list().then(res => {
      console.log(res)
      setData(res.data)
    })
       }, [])
       const myDelete = (row:any) => {
        service.consut_delete({ id: row.id}).then((res) => {
          console.log(res)
        })
        setTimeout(() => {
          navigate(0)
      }, 1000)
      }
    const columns= [
        {
          title: '序号',
          dataIndex: 'id',
          key: 'id',
        
        },
        {
          title: '列表图',
          dataIndex:'pic',
          key:'pic',
          render: (pic:any) => {
            return (
              <>
                 <img src={pic} alt="" />
              </>
           )
     }
        },
        {
          title: '文章标题',
          dataIndex: 'articletitle',
          key: 'articletitle',
        },
        {
          title: '文章分类',
          dataIndex: 'articlekind',
          key: 'articlekind',
        },
        {
          title: '发布人',
          dataIndex: 'person',
          key: 'person',
        },
        {
          title: '发布状态',
          dataIndex: 'pbulishStasus',
          key: 'pbulishStasus',
        },
        {
          title: '收藏量',
          dataIndex: 'collaction',
          key: 'collaction',
        },
        {
          title: '操作时间',
          dataIndex: 'endingtime',
          key: 'endingtime',
        },
   
        {
          title: '操作',
            render: (_: any, row: any) => {
                return (
                    <>
                 <span style={{marginRight:10,color:'blue'}}>编辑</span>
                        <span  style={{color:'red'}} onClick={()=>{myDelete(row)}}>删除</span>
                </>
             )
         }
        },
       
       
       
    ];
    return (
        <div className='system-consut'>
            <h4>咨询管理</h4>
            <div className='consut-header'>
                
                <TimeList></TimeList>
                <Button type="primary" >
          发布文章
        </Button>
            </div>
            <Table columns={columns} dataSource={data} />

            
        </div>
    );
}

export default SystemConsut;